package com.jhhe.mr.mysort;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class MySortMapper extends Mapper<LongWritable, Text, MySortBean, NullWritable> {
    final MySortBean bean = new MySortBean();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //1.读取一行文本，转为字符串
        final String field = value.toString();

        //2 解析出各个字段封装成bean
        bean.setNum(Long.parseLong(field));

        //3. MySortBean作为key输出
        context.write(bean, NullWritable.get());
    }
}
